package com.icid.store.command
{
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.adobe.cairngorm.control.CairngormEventDispatcher;
	import com.icid.store.business.delegate.CategoryDelegate;
	import com.icid.store.event.GetCategoryListEvent;
	import com.icid.store.event.SetCategoryInfoEvent;
	import com.icid.store.event.TryDeleteCategoryEvent;
	import com.icid.store.vo.CategoryVO;
	
	import mx.controls.Alert;
	import mx.rpc.IResponder;

	public class TryDeleteCategoryCommand extends CommandBase implements ICommand, IResponder
	{
		private var delegate:CategoryDelegate;
		private var tryDeleteCategoryEvent:TryDeleteCategoryEvent;
		public function TryDeleteCategoryCommand()
		{
			super();
			delegate = new CategoryDelegate(this);
		}
		
		override public function execute(event:CairngormEvent):void
		{
			tryDeleteCategoryEvent = TryDeleteCategoryEvent(event);
			delegate.delete_(tryDeleteCategoryEvent.cid);
		}
		
		override public function result(data:Object):void
		{
//			trace(data.result);
			switch(data.result.info)
			{
				case "success":
					Alert.show("Delete category success!","SUCCESS");
					CairngormEventDispatcher.getInstance().dispatchEvent(new GetCategoryListEvent(new CategoryVO()));
					break;
				case "failure":
					Alert.show("Delete category failure!","FAILURE");
					break;
				default:
					break;		
			}
		}
	}
}